//
//  TJConfirmOrderController.m
//  Teleport
//
//  Created by hc-101 on 2020/6/16.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJConfirmOrderController.h"
 
@interface TJConfirmOrderController ()

@property (strong, nonatomic) NSMutableArray *datas;
@property (weak, nonatomic) UIView *maskView;
@property (weak, nonatomic) UIView *contentView;

@end

  
@implementation TJConfirmOrderController



- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.modalPresentationStyle = UIModalPresentationCustom;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _datas = @[].mutableCopy;
 
//    coinNo = 2; 1,btc 2,usdt
//    buyType = 1;
//    payType = 2; 1,微信，2，支付宝，3，银行卡
//    unitPrice = 6.95; 单价
//    moneyType = 1; 1,cny 2,eur
//    entrustId = 222847901393760256; 委托id
//    entrustType = 1; 0.买单1.卖单
//    num = 14.388489;  数量
//    money = 100; 金额

    self.view.backgroundColor = UIColor.clearColor;
    
    UIView *maskView = [UIView tj_addToView:self.view];
    maskView.backgroundColor = [UIColor.tj_alertMaskColor colorWithAlphaComponent:0];
    maskView.frame = self.view.bounds;
    
    UIView *contentView = [UIView tj_addToView:maskView];
    contentView.backgroundColor = UIColor.whiteColor;
    UIView *headerView = [UIView tj_addToView:contentView];
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(50);
        make.top.offset(0);
    }];
 
    BOOL isBuy = [_dict[@"entrustType"] isEqualToString:@"1"];
    
    UILabel *nameLabel = [UILabel lableWithSuperView:headerView font:MediumFont(16) color:UIColor_Hex(0x272727) title:isBuy ? @"确定购买".localizedString : @"确定出售".localizedString textAlignment:NSTextAlignmentLeft];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
    }];
    
    UIButton *dismissButton = [UIButton buttonWithSuperView:headerView font:UIFont_Px(15) color:UIColor_Hex(0x272727) title:@"关闭".localizedString];
    [dismissButton addTarget:self action:@selector(didClickDismissButton) forControlEvents:UIControlEventTouchUpInside];
    [dismissButton setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentRight)];
     [dismissButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(nameLabel);
        make.width.height.offset(50);
        make.right.offset(-16);
    }];
    
    
    UILabel *totalLabel = [UILabel lableWithSuperView:contentView font:UIFont_Px(14) color:UIColor_Hex(0x272727) title:isBuy ? @"实付款".localizedString: @"实收款".localizedString textAlignment:NSTextAlignmentLeft];
       [totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(headerView.mas_bottom);
           make.right.equalTo(contentView.mas_centerX).offset(-50);
       }];
    
       UILabel *totalValueLabel = [UILabel lableWithSuperView:contentView font:MediumFont(14) color:UIColor_Hex(0x272727) title:[NSString stringWithFormat:@"¥%@", _dict[@"money"]] textAlignment:NSTextAlignmentLeft];
          [totalValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
              make.centerY.equalTo(totalLabel);
              make.left.equalTo(totalLabel.mas_right).offset(20);
          }];
    
     UILabel *payWayLabel = [UILabel lableWithSuperView:contentView font:UIFont_Px(14) color:UIColor_Hex(0x272727) title:isBuy ? @"付款方式".localizedString : @"收款方式".localizedString textAlignment:NSTextAlignmentLeft];
       [payWayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(totalLabel.mas_bottom).offset(10);
           make.right.equalTo(totalLabel);
       }];
    
       UILabel *payWayValueLabel = [UILabel lableWithSuperView:contentView font:MediumFont(14) color:UIColor_Hex(0x272727) title:[self payType] textAlignment:NSTextAlignmentLeft];
          [payWayValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
              make.centerY.equalTo(payWayLabel);
              make.left.equalTo(payWayLabel.mas_right).offset(20);
          }];
    
    UILabel *priceLabel = [UILabel lableWithSuperView:contentView font:UIFont_Px(14) color:UIColor_Hex(0x272727) title:@"单价".localizedString textAlignment:NSTextAlignmentLeft];
       [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(payWayLabel.mas_bottom).offset(10);
           make.right.equalTo(totalLabel);
       }];
 
    UILabel *priceValueLabel = [UILabel lableWithSuperView:contentView font:MediumFont(14) color:UIColor_Hex(0x272727) title:[NSString stringWithFormat:@"%@%@/%@", _dict[@"unitPrice"], [_dict[@"moneyType"] isEqualToString:@"1"] ? @"CNY" : @"EUR", [_dict[@"coinNo"] isEqualToString:@"1"] ? @"BTC" : @"USDT"] textAlignment:NSTextAlignmentLeft];
          [priceValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
              make.centerY.equalTo(priceLabel);
              make.left.equalTo(priceLabel.mas_right).offset(20);
          }];
    
    UILabel *numberLabel = [UILabel lableWithSuperView:contentView font:UIFont_Px(14) color:UIColor_Hex(0x272727) title:@"数量".localizedString textAlignment:NSTextAlignmentLeft];
       [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(priceLabel.mas_bottom).offset(10);
           make.right.equalTo(totalLabel);
       }];
    
       UILabel *numberValueLabel = [UILabel lableWithSuperView:contentView font:MediumFont(14) color:UIColor_Hex(0x272727) title:[NSString stringWithFormat:@"%@%@", _dict[@"num"], [_dict[@"coinNo"] isEqualToString:@"1"] ? @"BTC" : @"USDT"] textAlignment:NSTextAlignmentLeft];
          [numberValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
              make.centerY.equalTo(numberLabel);
              make.left.equalTo(numberLabel.mas_right).offset(20);
          }];
    
    
    UIButton *buyButton = [UIButton buttonWithSuperView:contentView font:UIFont_Px(15) color:UIColor.whiteColor title:@"确定".localizedString];
    buyButton.backgroundColor = UIColor.tj_mainColor;
    [buyButton shearRoundedCornersWithRadiu:18];
    [buyButton addTarget:self action:@selector(didClickBuyButton) forControlEvents:UIControlEventTouchUpInside];
    [buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(200);
         make.height.offset(36);
        make.centerX.offset(0);
        make.top.equalTo(numberValueLabel.mas_bottom).offset(25);
    }];
    
 
    
    CGFloat totalHeight = 200 + TabbarSafeBottomMargin + 50;
    contentView.frame = CGRectMake(0, KScreenHeight, KScreenWidth, totalHeight);
    
    _maskView = maskView;
    _contentView = contentView;
    
}

- (NSString *)payType {
    if ([_dict[@"payType"] intValue] == 1) {
        return @"微信".localizedString;

    } else if ([_dict[@"payType"] intValue] == 2) {
        return @"支付宝".localizedString;

    } else if ([_dict[@"payType"] intValue] == 3) {
        return @"银行卡".localizedString;
    }  else {
        return @"";
    }
}

- (void)didClickDismissButton {
    [self dismissComplete:nil];
}

- (void)didClickBuyButton {
    
    [self dismissComplete:^{
        if (self.selectComplete) {
            self.selectComplete();
        }
    }];
}

- (void)dismissComplete:(void (^)(void))complete {
    
    [UIView animateWithDuration:0.25 animations:^{
        self.maskView.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0];
        self.contentView.tj_y = KScreenHeight;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:^{
            if (complete) complete();
        }];
    }];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [UIView animateWithDuration:0.25 animations:^{
        self.maskView.backgroundColor = UIColor.tj_alertMaskColor;
        self.contentView.tj_y = KScreenHeight - self.contentView.tj_height;
    } completion:^(BOOL finished) {
    }];
}
 



@end
